package com.zhiwang.planet.widget

import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.viewpager.widget.ViewPager
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.zhiwang.planet.glide.transformation.RoundedCornersTransformation
import com.zhiwang.planet.util.dp

class SimpleNetWorkLoopingPagerAdapter(context: Context?, itemList: List<String>?, isInfinite: Boolean, var onItemClick: (Int) -> Unit) :
        LoopingPagerAdapter<String>(context, itemList, isInfinite) {


    override fun inflateView(viewType: Int, container: ViewGroup?, listPosition: Int): View {
        val imageView = ImageView(context)
        imageView.scaleType = ImageView.ScaleType.FIT_XY
        imageView.layoutParams = ViewPager.LayoutParams()
        return imageView
    }

    override fun bindView(convertView: View?, listPosition: Int, viewType: Int) {

        Glide.with(context)
                .load(itemList[listPosition])
                .apply(RequestOptions.bitmapTransform(
                        RoundedCornersTransformation(5.dp, 5.dp, RoundedCornersTransformation.CornerType.ALL)))
                .into(convertView as ImageView)


        convertView.setOnClickListener {
                onItemClick.invoke(listPosition)
        }
    }


}